
package it.lucci.ricochet.entities;

import java.awt.Graphics2D;
import java.awt.geom.Arc2D;
import java.awt.geom.Point2D;

/**
 * @author Gabriele Lucci
 * @version 1.0
 * Copyright 2012, Gabriele Lucci
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Ball implements Runnable {
    private double x;
    private double y;
    private double diameter;
    private double defaultSpeedX;
    private double defaultSpeedY;
    private double speedX;
    private double speedY;
    private boolean moving;

    public Ball() {
        this.moving = false;
    }
    /**
     * 
     * @param x
     * @param y
     * @param diameter 
     */
    public Ball(double x, double y, double diameter) {
        this.x = x;
        this.y = y;
        this.moving = false;
    }
    /**
     * 
     * @param x
     * @param y
     * @param diameter
     * @param defaultSpeedX
     * @param defaultSpeedY 
     */
    public Ball(double x, double y, double diameter, double defaultSpeedX, double defaultSpeedY) {
        this.x = x;
        this.y = y;
        this.defaultSpeedX = defaultSpeedX;
        this.defaultSpeedY = defaultSpeedY;
        this.moving = false;
    }
    
    public void move() {
        x += speedX;
        y += speedY;
    }
    public boolean hasHit(Pad pad) {
        if (this.lowestPoint().getY() >= pad.getY() 
                && this.lowestPoint().getY() <= pad.getY() 
                && this.center().getX() >= pad.getX()
                && this.center().getX() <= pad.getX()+pad.getWidth()) 
        {
            return(true);
        }
        return (false);
    }
    
    /**
     *
     */
    @Override
    public void run() {
        
    }
    /**
     * 
     * @return 
     */
    public Point2D.Double center(){
        return new Point2D.Double(this.x+(diameter/2), this.y+(diameter/2));
    }
    
    public Point2D.Double lowestPoint(){
        return new Point2D.Double(this.x+(diameter/2), this.y+diameter);
    }
    
    public Point2D.Double highestPoint(){
        return new Point2D.Double(this.x+(diameter/2), this.y);
    }
    
    public Point2D.Double rightmostPoint(){
        return new Point2D.Double(this.x+diameter, this.y+(diameter/2));
    }
    
    public Point2D.Double leftmostPoint(){
        return new Point2D.Double(this.x, this.y+(diameter/2));
    }

    public double getDiameter() {
        return diameter;
    }

    public void setDiameter(double diameter) {
        this.diameter = diameter;
    }
    
    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }

    public boolean isMoving() {
        return moving;
    }

    public void setMoving(boolean moving) {
        this.moving = moving;
    }

    public double getSpeedX() {
        return speedX;
    }

    public void setSpeedX(double speedX) {
        this.speedX = speedX;
    }

    public double getSpeedY() {
        return speedY;
    }

    public void setSpeedY(double speedY) {
        this.speedY = speedY;
    }

    public double getDefaultSpeedX() {
        return defaultSpeedX;
    }

    public void setDefaultSpeedX(double defaultSpeedX) {
        this.defaultSpeedX = defaultSpeedX;
    }
    /**
     * 
     * @return 
     */
    public double getDefaultSpeedY() {
        return defaultSpeedY;
    }
    /**
     * 
     * @param defaultSpeedY 
     */
    public void setDefaultSpeedY(double defaultSpeedY) {
        this.defaultSpeedY = defaultSpeedY;
    }
    /**
     * 
     * @param g2 
     */
    public void draw(Graphics2D g2){
        g2.fill(new Arc2D.Double(x, y, diameter, diameter, 0, 360, Arc2D.PIE));
    }
    /**
     * 
     * @return 
     */
    @Override
    public String toString() {
        return "Ball{" + "x=" + x + ", y=" + y + ", diameter=" + diameter + ", defaultXSpeed=" + defaultSpeedX + ", defaultYSpeed=" + defaultSpeedY + '}';
    }

}
